package panel.viewSpots
{
	import flash.display.Bitmap;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.text.TextField;
	
	import assists.HtmlText;
	import assists.TextFieldUtils;
	import assists.resource.ImageResource;
	import assists.resource.ResourceLoader;
	import assists.resource.ResourceLoaderData;
	
	import panel.viewSpots.navigation.ScrollTxtHor;
	
	import struct.Scenic;
	import struct.TourElementBase;
	
	public class AroundItem extends Sprite
	{
		private var _loader:ResourceLoader;
		private var _label:ScrollTxtHor;
		private var _icon:Bitmap;
		private var _shape:Shape = new Shape();
		private var _iconWid:int;
		private var _data:Object;
		public function AroundItem(loader:ResourceLoader,wid:int)
		{
			_loader = loader;
			_iconWid = wid;
			init();
		}
		
		private function init():void
		{
			_label = new ScrollTxtHor();
			
			
		}
		
		public function show(data:Object):void
		{
			_data = data;
			
			_icon = _loader.uiManager.generateBmp(_loader.uiManager.noPic,true);
			_icon.width = _icon.height = _iconWid;
			if(_data.url == "")
			{
				this.addChild(_icon);
				drawBlack(_data);
				return;
			}
			
			var self:AroundItem = this;
			self.addChild(_icon);
			var callBack:Function = function():void
			{
				if(_loader.getImage(data.url) != null)
				{
					self.removeChild(_icon);
				_icon = _loader.getImage(data.url);
				_icon.width = _icon.height = _iconWid;
				}
			
			self.addChild(_icon);
			drawBlack(data);
			}
			_loader.load([new ResourceLoaderData(data.url)],new Function,callBack);
		}
		
		private function drawBlack(data:Object):void
		{
			_label.showWid = _iconWid;
			_label.label(data.name,0xffffff);		
			
			_shape.graphics.beginFill(0,0.6);
			_shape.graphics.drawRect(0,_icon.height * 0.7,_icon.width,_icon.height * 0.3);
			_shape.graphics.endFill();
			
			_label.y = _icon.height * 0.7;
			this.addChild(_shape);
			this.addChild(_label);
			
		}
		
		override public function get width():Number
		{
			return _iconWid;
		}
		
		public function get data():Object
		{
			return _data;
		}
		
	}
}